﻿Imports HMSLibrary

Public Class AppointmentWindow

    Private Sub MasterWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        If FormType = FormsList.None Then Me.Close()
        Dim UCObject As Object = Nothing
        If FormType = FormsList.NextAppointment Then
            UCObject = New NextAppointmentControl(PatientID)
            ModuleNameRun.Text = HMSFormName.NextAppointment
        ElseIf FormType = FormsList.NextContact Then
            UCObject = New NextContactControl(PatientID)
            ModuleNameRun.Text = HMSFormName.NextContact
        ElseIf FormType = FormsList.NextRecall Then
            UCObject = New NextRecallControl(PatientID)
            ModuleNameRun.Text = HMSFormName.NextRecall
        End If
        If UCObject Is Nothing Then Exit Sub
        UCObject.Margin = New Thickness(10)
        MainStack.Children.Add(UCObject)
        If AppCommon.loginInfo.IsSuperUser = False Then ApplyPermission()
    End Sub

    Private Sub ApplyPermission()
        If AppCommon.loginInfo.IsSuperUser = True Then
            If FormType = FormsList.CompanyInfo Then
                MasterSidePanel.SaveVisibility = Visibility.Visible
            Else
                MasterSidePanel.AddVisibility = Visibility.Visible
                MasterSidePanel.FindVisibility = Visibility.Visible
                MasterSidePanel.SaveVisibility = Visibility.Visible
            End If
            Exit Sub
        End If
        Dim mp As ModulePermissions
        mp = (From ml In AppCommon.loginInfo.ModulesList Where ml.Name = ModuleNameRun.Text Select ml).FirstOrDefault
        If mp.Add = False Then MasterSidePanel.AddVisibility = Visibility.Collapsed Else MasterSidePanel.AddVisibility = Visibility.Visible
        If mp.Edit = False Then MasterSidePanel.FindVisibility = Visibility.Collapsed Else MasterSidePanel.FindVisibility = Visibility.Visible
        If mp.Print = False Then MasterSidePanel.PrintVisibility = Visibility.Collapsed Else MasterSidePanel.PrintVisibility = Visibility.Visible
    End Sub

    Private Sub MainWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        Try
            DragMove()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub

    Public Property FormType As FormsList = FormsList.None

    Private Sub MasterSidePanel_AddButtonClickEvent() Handles MasterSidePanel.AddButtonClickEvent
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.AddNew()
    End Sub

    Private Sub MasterSidePanel_BackButtonClickEvent() Handles MasterSidePanel.BackButtonClickEvent
        ApplyPermission()
        MasterSidePanel.BackVisibility = Visibility.Collapsed
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.BackView()
    End Sub

    Private Sub MasterSidePanel_CancelButtonClickEvent() Handles MasterSidePanel.CancelButtonClickEvent
        Me.Close()
    End Sub

    Private Sub MasterSidePanel_FindButtonClickEvent() Handles MasterSidePanel.FindButtonClickEvent
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.FindData()
        MasterSidePanel.PrintVisibility = Visibility.Collapsed
        MasterSidePanel.AddVisibility = Visibility.Collapsed
        MasterSidePanel.SaveVisibility = Visibility.Collapsed
        MasterSidePanel.FindVisibility = Visibility.Collapsed
        MasterSidePanel.BackVisibility = Visibility.Visible
    End Sub

    Private Sub MasterSidePanel_SaveButtonClickEvent() Handles MasterSidePanel.SaveButtonClickEvent
        Dim childObject As Object
        childObject = MainStack.Children(0)
        childObject.SaveData()
    End Sub

    Private PatientID As Long
    Public Sub New(ByVal _PatientID As Long)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.PatientID = _PatientID
    End Sub
End Class
